package com.example.config;

import xyz.lwm.lazycat.annotation.Bean;
import xyz.lwm.lazycat.utility.R;
import xyz.lwm.lazycat.utility.ThrowableUtil;
import xyz.lwm.lazycat.web.Exceptionable;
import xyz.lwm.lazycat.web.exception.ExceptionMapper;

@Bean
public class ExceptionAdaptor implements Exceptionable {
    @Override
    public void customize(ExceptionMapper exceptionMapper) {
        exceptionMapper.register(Exception.class, (e, ctx) -> {
            Throwable unwrapped = ThrowableUtil.unwrap(e);
            ctx.json(R.fail(unwrapped.getMessage()));
        });
    }
}
